import {
    Entity,
    PrimaryKey,
    Property,
    ManyToOne,
    Reference,
} from "@mikro-orm/core";
import { BaseEntity } from "./Base";
import { Author } from "./Author";

@Entity()
export class Book extends BaseEntity {
    @Property({ type: "string" })
    title: string;

    @ManyToOne({ entity: () => Author, nullable: true })
    author!: Reference<Author>; // response to filed 'author_id'

    constructor(title: string, author: Reference<Author>) {
        super();
        this.title = title;
        this.author = author;
    }
}
